package com.xpgk.mvc.statistic.zbStatistic;

import java.util.Date;
import java.util.List;

import com.xpgk.mvc.base.BaseController;
import com.xpgk.mvc.organization.Organization;
import com.xpgk.mvc.statistic.dailyTotalStatistic.DailyNursingTotal;
import com.xpgk.mvc.statistic.monthTotalStatistic.MonthTotal;
import com.xpgk.mvc.statistic.yearTotalStatistic.YearTotal;
import com.xpgk.tools.ToolDateTime;

public class ZbYearTotalStatisticController extends BaseController{
	
	public void  index()
	{	
		Organization organization = Organization.dao.findById(getCUserOrganIds());
		String year = ToolDateTime.format(new Date(), ToolDateTime.pattern_y);
		setAttr("year", year);
		setAttr("organization", organization);
		render("zbYearTotal.html");
	}
	
	public  void  getZbYearTotal()
	{
		String date  = getPara("year");
		String organids = getPara("organIds");
		Organization organization = Organization.dao.findById(organids);
		if(organization.getInt(Organization.column_level) == 4)//门店级别
		{	
			String sql = "SELECT scty.*,so.name orgname,so.kyTime,TIMESTAMPDIFF(MONTH,so.kyTime,NOW()) dl "+
						 " FROM sb_customer_total_year  scty  LEFT JOIN  sys_organization  so  ON scty.organids = so.ids "+
						 " WHERE scty.organids = ? AND  scty.date= ? ";
			List<YearTotal>  dnt = YearTotal.dao.find(sql,organids,date);
			renderJson(dnt);
		}else if(organization.getInt(Organization.column_level) == 3)//代理商级别
		{
			splitPage.getQueryParam().put("date", date);
			splitPage.getQueryParam().put("organids", organids);
			String json = paging(splitPage,MonthTotal.sqlId_getYearTotalSelect,MonthTotal.sqlId_getYearTotalForm);
			renderJson(json);
		}else
		{
			renderJson("");
		}
	}
}
